package com.lc.luzhengtang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.lc.luzhengtang.R;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by DR on 2016/5/31.订单评价5张图片
 */
public abstract class AddPicAdapter2 extends BaseAdapter {

    private Context context;

    private List<String> list;

    public AddPicAdapter2(Context context, List<String> list) {

        this.context = context;

        this.list = list;
    }

    @Override
    public int getCount() {

        return list.size();

    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;

        if (convertView == null) {

            convertView = LayoutInflater.from(context).inflate(R.layout.item_add_pic, null);


//BaseApplication.
            ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) convertView);
            holder = new ViewHolder();

            holder.img_add = (ImageView) convertView.findViewById(R.id.img_add);

            holder.img_del = (ImageView) convertView.findViewById(R.id.img_del);

            convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();

        }

        holder.img_del.setVisibility(View.VISIBLE);

        holder.img_del.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                list.remove(position);

                notifyDataSetChanged();

                deletePhoto();

            }

        });

        // BaseApplication.UtilAsyncSDCardBitmap.get(list.get(position), holder.img_add);

        return convertView;
    }

    private class ViewHolder {

        private ImageView img_add;

        private ImageView img_del;

    }

    public abstract void onPhoto();

    public abstract void deletePhoto();

}
